﻿using System;

namespace StudentEventHandler
{
    class Student: IPropertyChanged
    {
        private string firstName;
        private string lastName;
        private string gender;
        private DateTime birtDate;
        public event StudentInformationChandedEventHandler PropertyChanged;

        public Student(string firstName, string lastName, string gender, DateTime birtDate)
        {
            this.firstName = firstName;
            this.lastName = lastName;
            this.gender = gender;
            this.birtDate = birtDate;
        }

        public static void Person_PropertyChanged(object sender, StudentInformationChangedEventArg eventArgs)
        {
            if (eventArgs.OldValue != null)
            {
                Console.WriteLine("Student {0} was changed from {1} to {2}",
                    eventArgs.NameOfProperty, eventArgs.OldValue, eventArgs.NewValue);
            }
            else 
            {
                Console.WriteLine("Student {0} was changed from null to {0}",eventArgs.NameOfProperty,eventArgs.NewValue);
            }
        }

        protected void OnPropertyChanged(string propertyName, dynamic oldValue, dynamic newValue) 
        {
            if (propertyName != null)
            {
                StudentInformationChangedEventArg args =
                    new StudentInformationChangedEventArg(propertyName, newValue, oldValue);
                PropertyChanged(this, args);
            }
            else 
            {
                throw new ArgumentNullException("You haven`t specified a property to be changed");
            }
        }

        public string FirstName
        {
            get
            {
                return firstName;
            }
            set
            {
                if (value != null) 
                {
                    OnPropertyChanged("Firstname", this.FirstName, value);
                    firstName = value;
                }
            }
        }

        public string LastName
        {
            get
            {
                return lastName;
            }
            set
            {
                if (value != null) 
                {
                    OnPropertyChanged("Lastname", this.LastName, value);
                    lastName = value;
                }
            }
        }

        public string Gender
        {
            get
            {
                return gender;
            }
            set
            {
                if (value != null) 
                {
                    OnPropertyChanged("gender", this.Gender, value);
                    Console.WriteLine("Pola li she si smenqvash gad mrysna!!!");
                    gender = value;
                }
            }
        }

        public DateTime BirtDate
        {
            get
            {
                return birtDate;
            }
            set
            {
                if (value != null) 
                {
                    OnPropertyChanged("birthDate", this.BirtDate, value);
                    Console.WriteLine("E tova kak shte go smenish mi e interesno!?!??");
                    birtDate = value;
                }
            }
        }
    }
}
